<?php 
	$managers = array();
	$partners = array();
	foreach ($deals as $deal) {
		array_push($managers, $deal->manager);
		array_push($partners, $deal->partner);	
	}
	$managers = array_unique($managers);
	$partners = array_unique($partners);
?>
			<ul class="breadcrumb well">
						    <li><a href="#">Финансы</a> <span class="divider">/</span></li>
						    <li class="active">Все отчеты</li>
					    </ul>

						<div class="content well content-wide">
								<?php echo form_open('mgmt/financeReport/'); ?>
									<h5>Фильтр</h5>
									<input type="radio" name="rad" value="manager"> По менеджеру
									<select name="manager-select">
									<?php 
										foreach($managers as $manager){
											echo "<option value=".$manager.">".$manager."</option>";
										}

									?>
									</select><Br>

  									<input type="radio" name="rad" value="partner"> По партнеру
  									<select name="partner-select">
									<?php 
										foreach($partners as $partner){
											echo "<option value=".$partner.">".$partner."</option>";
										}

									?>
									</select><Br>
   									<input type="date" name="datefrom">с <input type="date" name="dateto"> до
									<input type="submit">
								</form>
					    	    <table class="table table-bordered table-hover">
					    	    	<thead>
										<tr>
											<td>Город</td>
											<td>Название предложения</td>
											<td>Партнер</td>
											<td>Менеджер</td>
											<td>Дата добавления</td>
											<td>Проданные купоны (кол-во + в тг.)  </td>
											<td>Активированные купоны (кол-во + в тг.)</td>
										</tr>
									</thead>

									<tbody>
					    	    		<?php foreach($deals as $deal){?>
										<tr class="text-normal">
											<?php if (isset($managerselected)){
												if($deal->manager != $managerselected){
													continue;
												}
											}?>
											<?php if (isset($partnerselected)){
												if($deal->partner != $partnerselected){
													continue;
												}
											}?>
											<?php
												if($datefrom != null && $dateto != null){
													if(strtotime(str_replace(" ", "-", $deal->adddate))<strtotime($datefrom) ||
											 			strtotime(str_replace(" ", "-", $deal->adddate))>strtotime($dateto)){
														continue;

												}
											
											}?>

											<td><?php echo $deal->city; ?></td>
											<td><?php echo $deal->dealname; ?></td>
											<td><?php echo $deal->partner; ?></td>
											<td><?php echo $deal->manager; ?></td>
											<td><?php echo $deal->adddate; ?></td>
											
											<td><?php echo $count_bought[$deal->id].' купонов '. $coupon_bought[$deal->id].' тг';?></td>
											<td><?php echo $count_active[$deal->id].' купонов '. $coupon_active[$deal->id].' тг'; ?></td>
										</tr>
										<?php }?>		
									</tbody>

    							</table>
					    </div> <!-- /content -->

					    
					    <!-- pagination -->